#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>

#define PORT 1200

int main()
{
        /* 创建socket */
        int sockfd = socket(AF_INET,SOCK_STREAM,0);
        if(sockfd == -1)
        {
                perror("socket failed!");
                exit(-1);
        }

	/* 准备地址 */
        struct sockaddr_in addr;
        addr.sin_family = AF_INET;
        addr.sin_port = htons(PORT);

	/* 修改为服务器所在主机IP地址 */
        inet_aton("192.168.8.192", &addr.sin_addr);

	/* 连接 */
        int res = connect(sockfd, (struct  sockaddr *)&addr,sizeof(addr));
        if(res == -1)
        {
                perror(" bind failed! ");
                exit(-1);
        }

	for(;;)
	{
		/* 收发数据 */
        	char *str = "Hello Server I am client!";
        	send(sockfd, str, strlen(str), 0);

		char buf[100] = {0};
        	read(sockfd, buf, sizeof(buf));
        	printf("receive from server:%s\n",buf);
	}
	/* 关闭 */
        close(sockfd);
        return 0;
        
}
